$(function () {
    $("#jqGrid").jqGrid({
        url: baseURL + 'erp/paperinfo/list',
        datatype: "json",
        colModel: [			
			{ label: 'paperInfoId', name: 'paperInfoId', index: 'paper_info_id', width: 50, key: true,hidden:true },
			{ label: '纸箱编码', name: 'paperCode', index: 'paper_code', width: 80 }, 			
			{ label: '纸质', name: 'paperName', index: 'paper_name', width: 80 }, 			
			{ label: '纸类', name: 'paperType', index: 'paper_type', width: 80 }, 			
			{ label: '默认重量', name: 'paperWeight', index: 'paper_weight', width: 80 }, 			
			{ label: '边压强度', name: 'sideStrength', index: 'side_strength', width: 80 }, 			
			{ label: '纸板耐破度', name: 'paperBreak', index: 'paper_break', width: 80 }, 			
			{ label: '厚度', name: 'paperHeight', index: 'paper_height', width: 80 }, 			
			{ label: '成本价', name: 'costMoney', index: 'cost_money', width: 80 }, 			
			{ label: '备注', name: 'remark', index: 'remark', width: 80 }, 			
			{ label: '停用(0:停用1:使用)', name: 'status', index: 'status', width: 80,hidden:true }			
        ],
		viewrecords: true,
        height: 385,
        rowNum: 10,
		rowList : [10,30,50],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" }); 
        }
    });
});

var vm = new Vue({
	el:'#rrapp',
	data:{
		showList: true,
		title: null,
		paperTypeList:[],
		paperInfo: {}
	},
	methods: {
		query: function () {
			vm.reload();
		},
		add: function(){
			vm.showList = false;
			vm.title = "新增";
			vm.paperInfo = {};
		},
		update: function (event) {
			var paperInfoId = getSelectedRow();
			if(paperInfoId == null){
				return ;
			}
			vm.showList = false;
            vm.title = "修改";
            
            vm.getInfo(paperInfoId)
		},
		saveOrUpdate: function (event) {
			var url = vm.paperInfo.paperInfoId == null ? "erp/paperinfo/save" : "erp/paperinfo/update";
			$.ajax({
				type: "POST",
			    url: baseURL + url,
                contentType: "application/json",
			    data: JSON.stringify(vm.paperInfo),
			    success: function(r){
			    	if(r.code === 0){
						alert('操作成功', function(index){
							vm.reload();
						});
					}else{
						alert(r.msg);
					}
				}
			});
		},
		del: function (event) {
			var paperInfoIds = getSelectedRows();
			if(paperInfoIds == null){
				return ;
			}
			
			confirm('确定要删除选中的记录？', function(){
				$.ajax({
					type: "POST",
				    url: baseURL + "erp/paperinfo/delete",
                    contentType: "application/json",
				    data: JSON.stringify(paperInfoIds),
				    success: function(r){
						if(r.code == 0){
							alert('操作成功', function(index){
								$("#jqGrid").trigger("reloadGrid");
							});
						}else{
							alert(r.msg);
						}
					}
				});
			});
		},
		getInfo: function(paperInfoId){
			$.get(baseURL + "erp/paperinfo/info/"+paperInfoId, function(r){
                vm.paperInfo = r.paperInfo;
            });
		},
		reload: function (event) {
			vm.showList = true;
			var page = $("#jqGrid").jqGrid('getGridParam','page');
			$("#jqGrid").jqGrid('setGridParam',{ 
                page:page
            }).trigger("reloadGrid");
		},
		queryPaperType() {
			$.get(baseURL + "erp/papertype/list", 
			{
	            page:{"currPage":1,"limit":10}
		        },
		        function(r){
	                if(r.code==0){
	                	vm.paperTypeList=r.page.list;
	                	debugger;
	                }
	            }
	        );
			
		}
	},
	mounted() {
	      this.queryPaperType();
	}
});